#include "mainwindow.h"
#include "./ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    setWindowTitle("RunningGame");
    stackedwidget=new QStackedWidget(this);
    setCentralWidget(stackedwidget);

    s=new startpage ;
    g=new gamepage;
    e=new endpage;

    stackedwidget->addWidget(s);
    stackedwidget->addWidget(g);
    stackedwidget->addWidget(e);

    connect(s,&startpage::StartGame,this,&MainWindow::startGame);
    connect(g,&gamepage::GameOver,this,&MainWindow::endGame);

}

MainWindow::~MainWindow()
{
    delete ui;
}
void MainWindow::startGame(){
    stackedwidget->setCurrentWidget(g);
    g->start();
}
void MainWindow::endGame(int score){
    e->setScore(score);
    stackedwidget->setCurrentWidget(e);
}
